home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / js.zip / ARITH.JS < prev    next >
Text File  |  1992-12-30  |  6KB  |  278 lines

  1.    NB.  This file can be used as a script input file to J Version 6.1
  2.    NB.  December 1992
  3.    
  4.    NB.  Donald B. McIntyre
  5.    NB.  Luachmhor, 1 Church Road
  6.    NB.  KINFAUNS, PERTH PH2 7LD
  7.    NB.  SCOTLAND - U.K.
  8.    NB.  Telephone:  In the UK:      0738-86-726
  9.    NB.  From USA and Canada:   011-1-738-86-726
  10.    NB.  email:  donald.mcintyre@almac.co.uk
  11.  
  12. NB.  VECTOR: The Journal of the British APL Association
  13. NB.  vol. 8, No. 3 (January 1991) p.101-123
  14. NB. p.102-103
  15.       add=. +
  16.       behead=. }.
  17.       copy=. #
  18.       divided_by=. %
  19.       double =. +:
  20.       floor=. <.
  21.       format=. ":
  22.       halve=. -:
  23.       head=. {.
  24.       increm=. >:
  25.       laminate=. .:
  26.       laminate=. ,:
  27.       larger_of=. >.
  28.       left=. [
  29.       lesser_of=. <.
  30.       less_or_equal=. <:
  31.       magnitude=. |
  32.       match=. -:
  33.       minus=. -
  34.       not=. -.
  35.       off=. 0!:55
  36.       one_minus=. -.
  37.       plus=. +
  38.       power=. ^
  39.       reciprocal=. %
  40.       residue=. |
  41.       reverse=. |.
  42.       right=. ]
  43.       show=. ]
  44.       shape=. $
  45.       signum=. *
  46.       tally=. #
  47.       times=. *
  48.       times_pi=. o.
  49.       transpose=. |:
  50.       tree=. 5!:4@<
  51.       wholes=. i.
  52.  
  53.       cross=. ~
  54.       fix=. f.
  55.       insert=. /
  56.       scan=. \
  57.  
  58.       atop=. after=. @
  59.       rank=. "
  60.       with=. &
  61.  
  62. NB. p.104
  63.       quarter=. % with 4
  64.       quarter wholes 12
  65.       f=. >:@i.
  66.       f 6
  67.       1 plus 1 plus 1 plus 1 plus 1
  68.       total=. plus insert
  69.       total 5 copy 1
  70.       total scan 10 copy 1
  71.       2 plus 2 plus 2 plus 2 plus 2 plus 2
  72.       total 6 copy 2
  73.       6 times 2
  74.       2 times 2 times 2 times 2 times 2 times 2
  75.       times insert 6 copy 2
  76.  
  77. NB. p.105
  78.       2 power 6
  79.       times insert 2 copy 6
  80.       6 power 2
  81.       2 copy cross 6
  82.       2 power~ 6
  83.       show i=. increm wholes 10
  84.       total increm wholes 10
  85.       i plus reverse i
  86.       halve 10 times 11
  87.       total increm wholes 100
  88.       1 2 3+100 99 98
  89.       halve 100 times increm 100
  90.       total increm wholes 1000
  91.       halve 1000 times increm 1000
  92.       halve (times increm) 1000
  93.  
  94. NB. p.106
  95.       i plus reverse i
  96.       (plus reverse) i
  97.       halve 100 times increm 100
  98.       halve (times increm) 100
  99.       spwn=. halve after (times increm)
  100.       spwn 1000
  101.       # _1 0 1 2 3 4 5
  102.  
  103. NB. p.107
  104.       (magnitude atop (minus insert)) _2 5
  105.       n=. |@(-/)
  106.       n _2 5
  107.       into=. %~
  108.       nsteps=. into n
  109.       0.5 nsteps _2 5
  110.       nsteps
  111.       nsteps=. nsteps fix
  112.       nsteps
  113.       nsteps=. (( %~ )(| @ ( -/ )))
  114.       0.5 nsteps _2 5
  115.  
  116. NB. p.108
  117.       nsteps=. %~ |@(-/)
  118.       0.5 nsteps _2 5
  119.      
  120.       list=. 9 3 4 _2 12 1 _4 15 7
  121.       list-<./list
  122.       q=. minus lesser_of insert
  123.       q list
  124.       q=. -<./
  125.       q list
  126.       p=. %>./
  127.       scale=. p@q
  128.       0.3 format scale list
  129.  
  130. NB. p.109
  131.       y=. 1 2 3 4
  132.       (total y) divided_by (tally y)
  133.       mean=. total divided_by tally
  134.       mean
  135.       tree 'mean'
  136.       mean=. mean fix
  137.       mean
  138.       mean 1 2 3 4
  139.       show y=. 1 10 100 1000 10000 into 1.2345
  140.  
  141. NB. p.110
  142.       0.01 (less_or_equal magnitude) y
  143.       clean=. right times (less_or_equal magnitude)
  144.       clean
  145.       tree 'clean'
  146.       x=. 0.01
  147.       y=. 1 10 100 1000 10000 into 1.2345
  148.       x clean y
  149.       x clean -y
  150.       f=. right times less_or_equal magnitude
  151.       f
  152.       f=. f fix
  153.       f
  154.  
  155. NB. p.111
  156.       g=. ]
  157.       h=. *<:|
  158.       x (g h) y
  159.       x g (h y)
  160.       h y
  161.       
  162.       p=. *
  163.       q=. <:
  164.       r=. |
  165.       (p q r) y
  166.       (p y) q (r y)
  167.       r y
  168.       p y
  169.       (* y) <: (|y)
  170.       f=. right times less_or_equal magnitude
  171.       x f y
  172.  
  173. NB. p.112
  174.       x=. 9 0.5 0 _0.5 _9
  175.       y=. _9 _1.5 _1 _0.5 0 1e_3 0.3 0.4 0.999 1 2 10 100
  176.  
  177.       over=.({.,.@;}.)@":@,
  178.       by=. ' '&;@,.@[,.]
  179.  
  180.       x by y over x f"0 1 y
  181.  
  182.       clean=. ] * (<:|)
  183.       clean
  184.  
  185.       show i=. wholes 10
  186.       10 plus i
  187.  
  188. NB. p.113
  189.       nl=. wholes minus floor atop halve
  190.       nl
  191.       nl=. i. - <.@-:
  192.       nl 11
  193.       1 10 100 1000 times"0 1 nl 11
  194.  
  195.       odd=. plus one_minus@(2&residue)
  196.       odd
  197.       odd=. + -.@(2&|)
  198.       odd
  199.       odd 2 4 6 8 laminate 1 3 5 7
  200.  
  201. NB. p.114
  202.       nline=. nl@odd
  203.       nline"0 right 12 13
  204.       nline"0 (12 13)
  205.       g=. i.@>.@>:@nsteps
  206.       0.5 g _2 5
  207.       0.5 g _2 5.2
  208.  
  209.       apv=. {.@] + [*g
  210.       0.5 apv _2 5
  211.       apv=. {.@] + [ * i.@>.@>:@(%~ |@-/)
  212.       0.5 apv _2 5
  213.  
  214. NB. p.115
  215.       times insert scan 10 10 10 10 10 10
  216.       10 power 1 2 3 4 5 6
  217.       10 power 0 1 2 3 4 5 6
  218.       10 power _4 _3 _2 _1 0 1 2 3 4 5 6
  219.       reciprocal 10 power _4 _3 _2 _1 0 1 2 3 4 5 6
  220.       place=. 10 with power
  221.       place 3
  222.       reverse place wholes 7
  223.       |. 10^ 1 apv _4 4
  224.  
  225. NB. p.116
  226.       100 *<.0.5+438%100
  227.       10 *<.0.5+26%10
  228.       0.1 *<.0.5+12.345%0.1
  229.       0.2 *<.0.5+12.345%0.2
  230.       round=. '' : 'x. * <. 0.5+ y.%x.'
  231.  
  232.       0.2 round 12.345
  233.       'x. * <. 0.5+ y.%x.' : 11
  234.       round=. [ * <.@(0.5&+@(%~))
  235.       round
  236.       0.2 round 12.345
  237.  
  238. NB. p.117
  239.       10 100 1000 round 146464
  240.       y=. 2 4 6 8
  241.       show x=. y round 146463
  242.       x%y
  243.       y=. 3 7 11 15 25 33 125
  244.       show x=. y round 146464
  245.       x%y
  246.  
  247.       (10^2) * <.0.5+438%10^2
  248.       rdp=. '' : '(10^x.) %~ <. 0.5+ y. * 10^x.'
  249.       0 1 2 3 4 5 rdp o.1
  250.       rdp=. 10&^@[ %~ <.@(0.5&+@((* 10&^)~))
  251.       0 1 2 3 4 5 rdp o.1
  252.  
  253. NB. p.118
  254.       (10^-i.6) round o.1
  255.  
  256.       h=. (]*<.@(0.5&+@%)) 10&^
  257.       rnd=. h~
  258.       0 _1 _2 _3 _4 _5 rnd o.1
  259.       x=. i.6
  260.       y=. 146464 14646 1464 146
  261.       table=. (10^x) round"0 1 y
  262.       y by x over transpose table
  263.  
  264.       table match x rnd"0 1 y
  265.       f=. ] * <.@(0.5&+@%)
  266.       h=. (f 10&^)~
  267.       table -: x h"0 1 y
  268.  
  269.       n,: 10 round n=. 12 26 165 14 38 43 56 65 97 145 235
  270.       n,: 100 round n=. 170 438 650 160 250 463 729 607 896 717 91 332 548
  271.       10 100 1000 round 8478
  272.  
  273. NB. p.119
  274.       n=. 8217 4096 7358 6105 8654 5583 7950 6008
  275.       p=. 10 100 1000
  276.       table=. |: p round"0 1 n
  277.       n by p over table
  278.